package com.leetcode.LC_MED;

import java.util.ArrayList;
import java.util.List;

public class LC78__2 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        dfs(nums, result, 0, new ArrayList<>());
        return result;
    }

    public void dfs(int[] nums, List<List<Integer>> result, int index, List<Integer> subset) {
        result.add(new ArrayList<>(subset));
        for (int i = index; i < nums.length; i++) {
            subset.add(nums[i]);
            dfs(nums, result, i + 1, subset);
            subset.remove(subset.size() - 1);
        }
    }

    public static void main(String[] args) {
        for (List<Integer> subset : new LC78__2().subsets(new int[]{1, 2, 3})) {
            System.out.println(subset);
        }
    }
}
